package com.game.common.utils;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.util.StringUtils;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

@Slf4j
public class MailUtil {
    public static void main(String[] args) {
        String emailHost = "smtp.qq.com";
        String emailUsername = "158314957@qq.com";
        String emailPassword = "zovzmupxkpejbgci";
        String emailTo = "741479997@qq.com";
        String emailSubject = "注册通知";
        HashMap<String, String> map = new HashMap<>();
        map.put("web_name", "SGO-Mall");
        map.put("web_name1", "SGO-Mall");
        map.put("email_to", "741479997@qq.com");
        map.put("content", "感谢您注册SGO，点击下发按钮注册");
        map.put("href", "https://baidu.com");
        map.put("href_name", "打开百度");
        map.put("web_email", "30974114@qq.com");
        String emailContent = getContent(map);
        System.out.println(emailContent);
        //sendAttachmentsMail(emailHost, emailUsername, emailPassword, emailTo, emailSubject, emailContent);
    }

    /**
     * 获取模版
     * map.put("web_name", "SGO-Mall"); 标题
     * map.put("web_name1", "Welcome to SGO-Mall"); 副标题
     * map.put("email_to", "741479997@qq.com"); 收件人
     * map.put("content", "感谢您注册SGO，点击下发按钮注册"); 内容
     * map.put("href", "https://baidu.com"); 链接
     * map.put("href_name", "打开百度"); 链接名称
     * map.put("web_email", "30974114@qq.com"); 联系邮件地址
     *
     * @param map
     * @return java.lang.String
     * @author 不愿透露
     * @date 2022/8/6 11:14
     */
    public static String getContent(Map<String, String> map) {
        String html = "<!DOCTYPE html>\n" +
                "<html>\n" +
                "<html>\n" +
                "<head>\n" +
                "    <meta charset=\"utf-8\">\n" +
                "    <title></title>\n" +
                "</head>\n" +
                "<body>\n" +
                "<div style=\"\n" +
                "\t\t    max-width: 600px;\n" +
                "\t\t    margin: 0 auto;\n" +
                "\t\t    font-family: PingFang SC;\n" +
                "\t\t    background-color: #fff;\n" +
                "\t\t  \">\n" +
                "    <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n" +
                "        <tbody>\n" +
                "        <tr>\n" +
                "            <td style=\"padding: 40px\">\n" +
                "\n" +
                "\n" +
                "                <img style=\"display: none;\" width=\"93\" height=\"15\"\n" +
                "                     src=\"https://img.myshopline.com/image/shopline/shoplinelogo.png\">\n" +
                "                <div style=\"\n" +
                "\t\t              max-width: 520px;\n" +
                "\t\t              margin: 0 auto 20px;\n" +
                "\t\t              line-height: 39px;\n" +
                "\t\t              font-weight: 700px;\n" +
                "\t\t              text-align: center;\n" +
                "\t\t              font-size: 32px;\n" +
                "\t\t              text-transform: uppercase;\n" +
                "\t\t              color: #1E1E1E;\n" +
                "\t\t            \">" + map.get("web_name") + "</div>\n" +
                "\n" +
                "                <h1 style=\"\n" +
                "\t\t              margin: 0 0 40px;\n" +
                "\t\t              color: #1e1e1e;\n" +
                "\t\t              font-weight: 600;\n" +
                "\t\t              font-size: 24px;\n" +
                "\t\t              line-height: 150%;\n" +
                "\t\t              text-align: center;\n" +
                "\t\t            \">\n" + map.get("web_name1") + " </h1>\n" +
                "\n" +
                "                <div style=\"\n" +
                "\t\t              margin-bottom: 40px;\n" +
                "\t\t              color: #1e1e1e;\n" +
                "\t\t              font-size: 14px;\n" +
                "\t\t              line-height: 150%;\n" +
                "\t\t            \">\n" +
                "                    <p>Hi," + map.get("email_to") + "!</p>\n" +
                "                    <p>" + map.get("content") + "</p>\n" +
                "                </div>\n" +
                "\n" +
                "                <a href=\"" + map.get("href") + "\"\n" +
                "                   target=\"_blank\" style=\"\n" +
                "\t\t              display: block;\n" +
                "\t\t              box-sizing: border-box;\n" +
                "\t\t              width: fit-content;\n" +
                "\t\t              min-width: 200px;\n" +
                "\t\t              max-width: 100%;\n" +
                "\t\t              margin: 0 auto;\n" +
                "\t\t              padding: 16px 32px;\n" +
                "\t\t              color: #FFFDFD;\n" +
                "\t\t              font-weight: 600;\n" +
                "\t\t              font-size: 16px;\n" +
                "\t\t              line-height: 22px;\n" +
                "\t\t              border-radius: 4px;\n" +
                "\t\t              background-color: #333333;\n" +
                "\t\t              text-align: center;\n" +
                "\t\t              text-decoration: none;\n" +
                "\t\t            \" rel=\"noopener\">\n" +
                "                    " + map.get("href_name") + "\n" +
                "                </a>\n" +
                "            </td>\n" +
                "        </tr>\n" +
                "\n" +
                "        <tr>\n" +
                "            <td style=\"padding: 32px; background-color: #f5f7f8; text-align: center\">\n" +
                "                <p style=\"text-align:center\">Need Help or Have Quesions? Feel free to contact us.</p>\n" +
                "                <p style=\"text-align:center\">We will do everything we can to provide you with a great\n" +
                "                    shopping experience. If you have any questions or feedback, please contact us at <a\n" +
                "                            href=\"mailto:" + map.get("web_email") + "\" rel=\"noopener\"\n" +
                "                            target=\"_blank\">" + map.get("web_email") + "</a></p>\n" +
                "                <p style=\"text-align:center\">This email was sent by " + map.get("web_name") + "</p>\n" +
                "            </td>\n" +
                "        </tr>\n" +
                "        </tbody>\n" +
                "    </table>\n" +
                "</div>" +
                "</body>\n" +
                "</html>\n";
        return html;
    }

    public static String getMsgContent(Map<String, String> map) {
        String html = "<style>\n" +
                "    @media only screen and (max-width: 600px) {\n" +
                "        .qmbox .inner-body {\n" +
                "            width: 100% !important;\n" +
                "        }\n" +
                "\n" +
                "        .qmbox .footer {\n" +
                "            width: 100% !important;\n" +
                "        }\n" +
                "    }\n" +
                "\n" +
                "    @media only screen and (max-width: 500px) {\n" +
                "        .qmbox .button {\n" +
                "            width: 100% !important;\n" +
                "        }\n" +
                "    }\n" +
                "</style>\n" +
                "<table class=\"wrapper\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\"\n" +
                "       style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; background-color: #f8fafc; margin: 0; padding: 0; width: 100%; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 100%;\">\n" +
                "    <tbody>\n" +
                "    <tr>\n" +
                "        <td align=\"center\"\n" +
                "            style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box;\">\n" +
                "            <table class=\"content\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" role=\"presentation\"\n" +
                "                   style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; margin: 0; padding: 0; width: 100%; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 100%;\">\n" +
                "                <tbody>\n" +
                "                <tr>\n" +
                "                    <td class=\"header\"\n" +
                "                        style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; padding: 25px 0; text-align: center;\">\n" +
                "                        <a href=\"" + map.get("href") + "\"\n" +
                "                           style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; color: #bbbfc3; font-size: 19px; font-weight: bold; text-decoration: none; text-shadow: 0 1px 0 white;\"\n" +
                "                           rel=\"noopener\" target=\"_blank\">" + map.get("web_name") + "\n" +
                "                        </a></td>\n" +
                "                </tr>\n" +
                "                <tr>\n" +
                "                    <td class=\"body\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"\n" +
                "                        style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; background-color: #ffffff; border-bottom: 1px solid #edeff2; border-top: 1px solid #edeff2; margin: 0; padding: 0; width: 100%; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 100%;\">\n" +
                "                        <table class=\"inner-body\" align=\"center\" width=\"570\" cellpadding=\"0\" cellspacing=\"0\"\n" +
                "                               role=\"presentation\"\n" +
                "                               style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; background-color: #ffffff; margin: 0 auto; padding: 0; width: 570px; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 570px;\">\n" +
                "                            <tbody>\n" +
                "                            <tr>\n" +
                "                                <td class=\"content-cell\"\n" +
                "                                    style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; padding: 35px;\">\n" +
                "                                    <p\n" +
                "                                            style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; color: #3d4852; font-size: 16px; line-height: 1.5em; margin-top: 0; text-align: left;\">\n" +
                "                                        Hello, " + map.get("userName") + ":<br></p>\n" +
                "                                    <p\n" +
                "                                            style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; color: #3d4852; font-size: 16px; line-height: 1.5em; margin-top: 0; text-align: left;\">\n" +
                "                                        For your feedback:</p>\n" +
                "                                    <table class=\"panel\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"\n" +
                "                                           role=\"presentation\"\n" +
                "                                           style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; margin: 0 0 21px;\">\n" +
                "                                        <tbody>\n" +
                "                                        <tr>\n" +
                "                                            <td class=\"panel-content\"\n" +
                "                                                style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; background-color: #f1f5f8; padding: 16px;\">\n" +
                "                                                <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"\n" +
                "                                                       role=\"presentation\"\n" +
                "                                                       style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box;\">\n" +
                "                                                    <tbody>\n" +
                "                                                    <tr>\n" +
                "                                                        <td class=\"panel-item\"\n" +
                "                                                            style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; padding: 0;\">\n" +
                "                                                            <p\n" +
                "                                                                    style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; color: #3d4852; font-size: 16px; line-height: 1.5em; margin-top: 0; text-align: left; margin-bottom: 0; padding-bottom: 0;\">\n" +
                "                                                                " + map.get("forYour") + "</p>\n" +
                "                                                        </td>\n" +
                "                                                    </tr>\n" +
                "                                                    </tbody>\n" +
                "                                                </table>\n" +
                "                                            </td>\n" +
                "                                        </tr>\n" +
                "                                        </tbody>\n" +
                "                                    </table>\n" +
                "                                    <p\n" +
                "                                            style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; color: #3d4852; font-size: 16px; line-height: 1.5em; margin-top: 0; text-align: left;\">\n" +
                "                                        Our response is as follows:</p>\n" +
                "                                    <table class=\"panel\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"\n" +
                "                                           role=\"presentation\"\n" +
                "                                           style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; margin: 0 0 21px;\">\n" +
                "                                        <tbody>\n" +
                "                                        <tr>\n" +
                "                                            <td class=\"panel-content\"\n" +
                "                                                style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; background-color: #f1f5f8; padding: 16px;\">\n" +
                "                                                <table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"\n" +
                "                                                       role=\"presentation\"\n" +
                "                                                       style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box;\">\n" +
                "                                                    <tbody>\n" +
                "                                                    <tr>\n" +
                "                                                        <td class=\"panel-item\"\n" +
                "                                                            style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; padding: 0;\">\n" +
                "                                                            <p\n" +
                "                                                                    style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; color: #3d4852; font-size: 16px; line-height: 1.5em; margin-top: 0; text-align: left; margin-bottom: 0; padding-bottom: 0;\">\n" +
                "                                                                " + map.get("our") + "</p>\n" +
                "                                                        </td>\n" +
                "                                                    </tr>\n" +
                "                                                    </tbody>\n" +
                "                                                </table>\n" +
                "                                            </td>\n" +
                "                                        </tr>\n" +
                "                                        </tbody>\n" +
                "                                    </table>\n" +
                "                                    <table class=\"action\" align=\"center\" width=\"100%\" cellpadding=\"0\"\n" +
                "                                           cellspacing=\"0\" role=\"presentation\"\n" +
                "                                           style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; margin: 30px auto; padding: 0; text-align: center; width: 100%; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 100%;\">\n" +
                "                                        <tbody>\n" +
                "                                        <tr>\n" +
                "                                            <td align=\"center\"\n" +
                "                                                style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box;\">\n" +
                "                                                <table width=\"100%\" border=\"0\" cellpadding=\"0\"\n" +
                "                                                       cellspacing=\"0\" role=\"presentation\"\n" +
                "                                                       style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box;\">\n" +
                "                                                    <tbody>\n" +
                "                                                    <tr>\n" +
                "                                                        <td align=\"center\"\n" +
                "                                                            style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box;\">\n" +
                "                                                            <table border=\"0\" cellpadding=\"0\"\n" +
                "                                                                   cellspacing=\"0\"\n" +
                "                                                                   role=\"presentation\"\n" +
                "                                                                   style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box;\">\n" +
                "                                                                <tbody>\n" +
                "                                                                <tr>\n" +
                "                                                                    <td\n" +
                "                                                                            style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box;\">\n" +
                "                                                                        <a href=\"" + map.get("href") + "\"\n" +
                "                                                                           class=\"button button-primary\"\n" +
                "                                                                           target=\"_blank\"\n" +
                "                                                                           style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; border-radius: 3px; box-shadow: 0 2px 3px rgba(0, 0, 0, 0.16); color: #fff; display: inline-block; text-decoration: none; -webkit-text-size-adjust: none; background-color: #3490dc; border-top: 10px solid #3490dc; border-right: 18px solid #3490dc; border-bottom: 10px solid #3490dc; border-left: 18px solid #3490dc;\"\n" +
                "                                                                           rel=\"noopener\">Continued\n" +
                "                                                                            Feedback</a>\n" +
                "                                                                    </td>\n" +
                "                                                                </tr>\n" +
                "                                                                </tbody>\n" +
                "                                                            </table>\n" +
                "                                                        </td>\n" +
                "                                                    </tr>\n" +
                "                                                    </tbody>\n" +
                "                                                </table>\n" +
                "                                            </td>\n" +
                "                                        </tr>\n" +
                "                                        </tbody>\n" +
                "                                    </table>\n" +
                "                                    <p\n" +
                "                                            style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; color: #3d4852; font-size: 16px; line-height: 1.5em; margin-top: 0; text-align: left;\">\n" +
                "                                        Thanks,<br>" + map.get("web_name") + "</p>\n" +
                "                                </td>\n" +
                "                            </tr>\n" +
                "                            </tbody>\n" +
                "                        </table>\n" +
                "                    </td>\n" +
                "                </tr>\n" +
                "                <tr>\n" +
                "                    <td\n" +
                "                            style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box;\">\n" +
                "                        <table class=\"footer\" align=\"center\" width=\"570\" cellpadding=\"0\" cellspacing=\"0\"\n" +
                "                               role=\"presentation\"\n" +
                "                               style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; margin: 0 auto; padding: 0; text-align: center; width: 570px; -premailer-cellpadding: 0; -premailer-cellspacing: 0; -premailer-width: 570px;\">\n" +
                "                            <tbody>\n" +
                "                            <tr>\n" +
                "                                <td class=\"content-cell\" align=\"center\"\n" +
                "                                    style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; padding: 35px;\">\n" +
                "                                    <p\n" +
                "                                            style=\"font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; line-height: 1.5em; margin-top: 0; color: #aeaeae; font-size: 12px; text-align: center;\">\n" +
                "                                        © 2022 " + map.get("web_name") + ". Version: all。</p>\n" +
                "                                </td>\n" +
                "                            </tr>\n" +
                "                            </tbody>\n" +
                "                        </table>\n" +
                "                    </td>\n" +
                "                </tr>\n" +
                "                </tbody>\n" +
                "            </table>\n" +
                "        </td>\n" +
                "    </tr>\n" +
                "    </tbody>\n" +
                "</table>\n" +
                "<style type=\"text/css\">\n" +
                "    .qmbox style,\n" +
                "    .qmbox script,\n" +
                "    .qmbox head,\n" +
                "    .qmbox link,\n" +
                "    .qmbox meta {\n" +
                "        display: none !important;\n" +
                "    }\n" +
                "</style>";
        return html;
    }

    /**
     * 带附件的邮件
     *
     * @param mail MailUtil.mail
     * @emailHost 地址
     */
    public static boolean sendMail(Mail mail) {
        try {
            if (StringUtils.isEmpty(mail.getHost())) {
                throw new RuntimeException("发件服务器不能为空!");
            }
            if (StringUtils.isEmpty(mail.getUsername())) {
                throw new RuntimeException("发件账号不能为空!");
            }
            if (StringUtils.isEmpty(mail.getPassword())) {
                throw new RuntimeException("发件密码不能为空!");
            }
            if (StringUtils.isEmpty(mail.getPort())) {
                throw new RuntimeException("发件端口不能为空!");
            }
            if (StringUtils.isEmpty(mail.getEncryption())) {
                throw new RuntimeException("加密方式不能为空!");
            }
            if (StringUtils.isEmpty(mail.getEmailTo())) {
                throw new RuntimeException("发件人不能为空!");
            }
            if (StringUtils.isEmpty(mail.getSubject())) {
                throw new RuntimeException("发件标题不能为空!");
            }
            if (StringUtils.isEmpty(mail.getContent())) {
                throw new RuntimeException("发件内容不能为空!");
            }
            //创建实例
            JavaMailSenderImpl sender = new JavaMailSenderImpl();
            //设置发送的服务器（这里的属性 qq和网易的不一样）qq：smtp.qq.com   网易：smtp.126.com
            sender.setHost(mail.getHost());
            //当前发送人邮箱（也就是自己）
            sender.setUsername(mail.getUsername());
            //授权码 （不是邮箱密码  是上面咱们的准备工作获取的那个码）
            sender.setPassword(mail.getPassword());
            //设置端口（这里用456、默认的25 在阿里云服务器上未开放，推荐我们设置456）
            sender.setPort(Integer.valueOf(mail.getPort()));
            sender.setDefaultEncoding("ssl");
            //然后设置456需要设置底下一些东西、之前这写我写到yml里，就是不清楚该怎么去修改。
            Properties p = new Properties();
            p.setProperty("mail.smtp.auth", "true");
            p.setProperty("mail.smtp.ssl", "true");
            p.setProperty("mail.smtp.socketFactory.port", mail.getPort());
            p.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
            p.setProperty("mail.smtp.starttls.enable", "true");
            p.setProperty("mail.smtp.starttls.required", "true");
            sender.setJavaMailProperties(p);
            MimeMessage message = sender.createMimeMessage();
            //解决-发送邮件时附件名太长会被截取掉或者中文乱码问题
            System.getProperties().setProperty("mail.mime.splitlongparameters", "false");
            //这里的utf-8解决 邮件 内容乱码
            MimeMessageHelper helper = new MimeMessageHelper(message, true, "utf-8");
            //当前发送人邮箱（也就是自己）
            helper.setFrom(mail.getUsername());
            //发送到的邮箱地址
            helper.setTo(mail.getEmailTo());
            //邮件主题、标题
            helper.setSubject(mail.getSubject());
            //类容
            helper.setText(mail.getContent(), true);
            //多个这样创建
            // helper.addAttachment(attachmentsMailNameDispose(uploadEXECL), file);
            // helper.addAttachment(attachmentsMailNameDispose(uploadCAD), file);
            sender.send(message);
            //日志信息
            log.info("邮件已经发送。");
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }

    @Data
    public static class Mail {
        /**
         * 发件服务器
         */
        private String host;
        /**
         * 发件端口
         */
        private String port;
        /**
         * 加密协议
         */
        private String encryption;
        /**
         * 发件人
         */
        private String username;
        /**
         * 发件密码
         */
        private String password;
        /**
         * 收件人
         */
        private String emailTo;
        /**
         * 发件标题
         */
        private String subject;
        /**
         * 发件内容
         */
        private String content;
    }

    public enum MailEnum {
        REGISTER(0, "注册"),
        VERIFY_MAIL(1, "验证邮箱"),
        CREATE_ORDER(2, "下单通知"),
        PAID_ORDER(3, "已付款通知"),
        SHIPPED_ORDER(4, "发货通知"),
        CLOSE_ORDER(5, "关闭订单通知"),
        SEND_MSG(6, "发送消息"),
        RESET_PASSWORD(7, "找回密码");
        private Integer code;
        private String name;

        MailEnum(Integer code, String name) {
            this.code = code;
            this.name = name;
        }

        public Integer getCode() {
            return code;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}
